//
// Created by sjjmw on 3/24/2022.
//
#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"
#include "unordered_map"
#include "cmath"
#include<iomanip>
#include "string"
#include "map"
struct Sol{
    std::vector<int> buf;
    int cl(int k){
        int wp=0;
        for(int i=0;i<4;i++){
            if(k){
                buf[i]=k%10;
                k/=10;
            }else{
                buf[i]=0;
            }
        }

        std::sort(buf.begin(),buf.end());
        int small=0;
        int big=0;
        for(int i=0;i<buf.size();i++){
            small*=10;
            small+=buf[i];
        }
        for(int i=buf.size()-1;i>=0;i--){
            big*=10;
            big+=buf[i];
        }
        return big-small;
    }
    void handle(int k){
        buf.resize(4);
        int step=0;
        while(k!=6174){
            step++;
            k=cl(k);
        }
        printf("%d\n",step);
        ;
    }
};
int main(){
    int a,b,c;
//    std::string str;
    while (std::cin>>a){
        Sol().handle(a);
    }
    return 0;
}